#include <stdio.h>
#include "ax_vector.h"
#include "com.h"
#include "ax_printf.h"
static int test_push_type()
{
    ax_vector* v = ax_vector_create(100, sizeof(char));

    ax_info("push char.\n");
    char A = 'A';
    char B = 'B';
    ax_vector_push_back(v, &A);
    ax_vector_push_back(v, &B);
    char* item;
    ax_vector_foreach2(char, item, v)
    {
        ax_info("%c ", *item);
    }
    ax_info("\n");

    ax_vector_clear(v);

    v = ax_vector_create(100, sizeof(int));

    ax_info("push int.\n");
    int a = 10;
    int b = 20;
    ax_vector_push_back(v, &a);
    ax_vector_push_back(v, &b);
    ax_vector_set(v, 1, &a);
    for(int i=0;i<ax_vector_size(v);i++)
    {
        int* value = ax_vector_at(v, i);
        ax_info("%d ", *value);
    }
    ax_info("\n");


    return 0;
}
int main(int argc, char* argv[])
{
    return test_push_type();
    ax_vector* vec = ax_vector_create(5, 0);
    for(size_t i=0;i<5;i++)
    {
        size_t* v = ALLOC(size_t);
        *v = i;
        ax_vector_push_back(vec, v);
    }

    for(size_t i=0;i<ax_vector_size(vec);i++)
    {
        ax_debug("value[%d]: %d\n",i, *(size_t*)ax_vector_at(vec, i));
    }

    size_t* data = ax_vector_erase(vec, 3);
    FREE(data);



    ax_debug("vec size:%d\n", ax_vector_size(vec));
    size_t* d;
    ax_vector_foreach(d, vec)
    {
        ax_debug("value2[%d]: %d\n",i, *d);
    }

    ax_vector_reserve(vec, 10);
    ax_debug("vec size when reserve:%d\n", ax_vector_size(vec));
    ax_vector_foreach(d, vec)
    {
        ax_debug("value2[%d]: %d\n",i, *d);
    }

    ax_vector_resize(vec, 15);
    ax_debug("vec size when resize:%d\n", ax_vector_size(vec));
    ax_vector_foreach(d, vec)
    {
        if(d)
         ax_debug("value2[%d]: %d\n",i, *d);
    }

    for(int i=5;i<25;i++)
    {
        size_t* v = ALLOC(size_t);
        *v = i;
        ax_vector_push_back(vec, v);
    }
    ax_debug("vec size when push back. grow:%d\n", ax_vector_size(vec));
    ax_vector_foreach(d, vec)
    {
        if(d)
            ax_debug("value2[%d]: %d\n",i, *d);
    }

    while(ax_vector_size(vec)>0)
    {
        size_t* v = ax_vector_erase(vec, 0);
        FREE(v);
    }
    ax_debug("vec size when clear.%d\n", ax_vector_size(vec));

    return 0;
}
